package com.zx.designpattern.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.zx.designpattern.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @作者 Administrator
 * @创建时间 2018-02-03 22:21
 * @描述 GirlAdapter
 * @修改时间 2018-02-03 22:21
 * @修改描述
 * @修改者 Administrator
 **/
public class GirlAdapter extends BaseAdapter {
    List<String> data;
    LayoutInflater mInflater;

    public GirlAdapter(Context context, List data) {
        this.data = data;
        if (this.data == null) {
            this.data = new ArrayList();
        }
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mViewHolder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_girl, null);
            mViewHolder = new ViewHolder(convertView);
            convertView.setTag(mViewHolder);
        } else {
            mViewHolder = (ViewHolder) convertView.getTag();
        }

        mViewHolder.show(data.get(position));
        return convertView;
    }

    class ViewHolder {
        View root;
        @BindView(R.id.text)
        TextView text;

        public ViewHolder(View root) {
            this.root = root;
            ButterKnife.bind(this,this.root);
        }

        public void show(String data) {

            text.setText(data);
        }
    }

    public void clearData() {
        this.data.clear();
        this.notifyDataSetChanged();
    }

    public void addData(List data) {
        this.data.addAll(data);
        this.notifyDataSetChanged();

    }
}
